<%@ page import="com.dd.domain.Product" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<body>
    <form name="cx" action="#" method="post">
        <input type="text" id="productname" name="pname" placeholder="输入查询产品名称">
        <input type="submit" value="查询">
    </form>

    <table id="table01" border="1">
        <tr>
            <td>产品编码</td>
            <td>产品名称</td>
            <td>产品类型</td>
            <td>产品价格</td>
            <td>操作</td>
        </tr>
        <%
            // 获取共享对象
            List<Product> data = (ArrayList) session.getAttribute("productdata");
            for (Product p : data){
        %>

        <tr>
            <td><%= p.getPid() %></td>
            <td><%= p.getPname() %></td>
            <td><%= p.getPtid().getPtname() %> </td>
            <td><%= p.getPprice() %></td>
            <td>添加</td>
        </tr>

        <%
            }
        %>

    </table>


    <br/>
    <br/>
    <button id="shop">显示更多</button>

    <script type="text/javascript" src="js/jquery/jquery-3.4.1.js"></script>
    <script>
        var pageNum = 1;

        $("#shop").click(function(){


            $.ajax({
                type: "post",
                async: true,
                dataType: "json",
                data: "d01=" + pageNum,
                url: "shop.do",

                success: function(data){
                    pageNum++;

                    var content="";
                    $.each(data,function (i,product) {
                        content+="<tr>";
                        content+="<td>"+product["pid"]+"</td>"+"<td>"+product["pname"]+"</td>"+"<td>"+product["ptid"]["ptname"]+"</td>"+"<td>"+product["pprice"]+"</td>"+"<td>添加</td>";
                        content+="</tr>";



                    });
                    $("#table01").append(content);


                }
            });

        });

    </script>
</body>
</html>
